package com.cqch.utils;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.stereotype.Component;

/**
 * @Author CQCH
 * @Description  手机号注册登录  阿里云短信
 * @Date 2022/3/29
 */
@Component
public class Sample {
    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        Client client = new Client(config);
        System.out.println(client);
        return client;
    }
//
//    public static void main(String[] args_) throws Exception {
//        com.aliyun.dysmsapi20170525.Client client = Sample.createClient("LTAI5tBtsHxtqjBRcfWXBjnL", "3pUEsTH8bgNR1ZI2kmlYd7s7tkrMCq");
//       String s= "123456";
//        SendSmsRequest sendSmsRequest = new SendSmsRequest()
//
//                .setSignName("阿里云短信测试")
//                .setTemplateCode("SMS_154950909")
//                .setPhoneNumbers("13891755920")
//                .setTemplateParam("{\"code\":"+s+"}");
//        // 复制代码运行请自行打印 API 的返回值
//        SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
//        System.out.println(sendSmsResponse);
//        com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(sendSmsResponse)));
//
//    }
}